package com.hazardSoft.eStore.entities;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Transient;

import com.hazardSoft.eStore.utils.QueryConstants;

@Entity
@NamedQueries({
	@NamedQuery(name = QueryConstants.QUERY_LIST_USERS, query = "FROM User u ORDER BY u.name ASC"),
	@NamedQuery(name = QueryConstants.QUERY_SEARCH_USER_BY_LOGIN, query = "FROM User usr WHERE usr.login=?1")
})
public class User implements Serializable {
	
	@Id
	private Integer id;

	@Lob
	private String name;
	
	private String login;
	
	private String password;

	private Long socialnumber;

	@Lob
	private String address;

	private Integer telephone;

	@Lob
	private String email;

	@ManyToOne
	@JoinColumn(name="city")
	private City city;

	@ManyToOne
	@JoinColumn(name="role")
	private Role role;

	@ManyToOne
	@JoinColumn(name="office")
	private Office office;

//	@OneToMany(mappedBy="seller")
	@Transient
	private List<Bill> billCollection;

//	@OneToMany(mappedBy="client")
//	private Collection<Check> checkCollection2;

	private static final long serialVersionUID = 1L;

	public User() {
		super();
	}

	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Long getSocialnumber() {
		return this.socialnumber;
	}

	public void setSocialnumber(Long socialnumber) {
		this.socialnumber = socialnumber;
	}

	public String getAddress() {
		return this.address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public Integer getTelephone() {
		return this.telephone;
	}

	public void setTelephone(Integer telephone) {
		this.telephone = telephone;
	}

	public String getEmail() {
		return this.email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public City getCity() {
		return this.city;
	}

	public void setCity(City city) {
		this.city = city;
	}

	public Role getRole() {
		return this.role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	public Office getOffice() {
		return this.office;
	}

	public void setOffice(Office office) {
		this.office = office;
	}

	public List<Bill> getBillCollection() {
		return this.billCollection;
	}

	public void setBillCollection(List<Bill> billCollection) {
		this.billCollection = billCollection;
	}

	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	

//	public Collection<Check> getCheckCollection2() {
//		return this.checkCollection2;
//	}
//
//	public void setCheckCollection2(Collection<Check> checkCollection2) {
//		this.checkCollection2 = checkCollection2;
//	}

	public String toString(){
		StringBuffer userString = new StringBuffer();
		
		userString.append("id: ["+this.getId()+"] ");
		userString.append("name: ["+this.getName()+"] ");
		userString.append("login: ["+this.getLogin()+"] ");
		userString.append("password: ["+this.getPassword()+"] ");
		userString.append("socialNumber: ["+this.getSocialnumber()+"] ");
		userString.append("address: ["+this.getAddress()+"] ");
		userString.append("telephone: ["+this.getTelephone()+"] ");
		userString.append("email: ["+this.getEmail()+"] ");
		userString.append("city: ["+this.getCity()+"] ");
		userString.append("office: ["+this.getOffice()+"] ");
		
		return userString.toString();
	}	
}
